<?php
require_once 'plugins/sfPropelPlugin/lib/propel/builder/SfObjectBuilder.php';

class OfPropelObjectBuilder extends SfObjectBuilder
{
  
	
  protected function addClassBody(&$script)
  {
  	self::addReplaceInto($script);
  	parent::addClassBody($script);
  }
  
  protected function addReplaceInto(&$script)
  {
  	
  	$className = $this->getTable()->getPhpName();
  	
  	$script .="

  /**
   * \$object->replaceInto('ColTitle', 'ColDate');
   * 
   */
  public function replaceInto()
  {
    \$columns = func_get_args();
    \$object = new {$className}();
    
    foreach((array)\$columns as \$col)
    {
      \$object->setByName(\$col, \$this->getByName(\$col));
    }
    
    \$rs = \$object->getPeer()->doSelectOne(\$object->buildCriteria());
    if(\$rs)
    {
      \$this->setId(\$rs->getId());
      \$this->setNew(false);
    }
    
    \$this->save();
    
  }
  
  	";
  	
  }
}